package com.itheima.Controller;

import com.itheima.domain.Book;

import java.util.List;
import java.util.Scanner;

public class FindBookName {

    Scanner sc = new Scanner(System.in);

    //通过书名来查看书籍
    public String findName(List<Book> list) {
        //获取要查询的书籍名

        System.out.println("请输入您要查看的书籍名");
        String bookName = sc.next();
        //判断书籍是否存在
        if ("exit".equals(bookName)){
            return null;
        }
        boolean exists = isExists(list, bookName);
        //书籍存在和不存在的操作
        if (!exists) {

            System.out.println("您查询的书籍不存在");
        }
        return bookName;
    }

    //判断书籍是否存在
    public boolean isExists(List<Book> list, String bookName) {
        boolean flag = false;
        for (Book book : list) {
            String bookTitle = book.getBookTitle();

            if (book.getBookId().equals(bookName)) {
                flag = true;
            }
        }
        return flag;
    }

    //书籍存在,后续的操作
    public void readBook(String bookId) {
        lo:
        while (true) {
            System.out.println("请输入您的需求: 1,查看小说内容 2,退出");
            int choose = sc.nextInt();
            switch (choose) {
                case 1:
                    //根据id 来查看小说内容
                    System.out.println("查看内容");//*******************************需要调用阅读小说章节的方法或者类***********************************//
                    break lo;
                case 2:
                    break lo;
                default:
                    System.out.println("您的输入有误");
            }
        }
    }
}



